# _*_ coding: UTF-8 _*_
# @Time     : 2021/11/4 13:40
# @Author   : 郑鲁明
# @Site     : http://www.hzdledu.cn/
# @File     : date_entry.py
# @Software : PyCharm
from selenium.webdriver.support.wait import WebDriverWait  # 等待类
from selenium.webdriver.support import expected_conditions  # 等待条件
from selenium.webdriver.common.by import By  # 定位符
from selenium import webdriver
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select


class DateEntry():
    def __init__(self, driver):
        # 导航栏—招聘管理
        self.rec_management = (By.XPATH, '//*[@id="root"]/section/aside/div/ul/li[1]/div')
        # 导航栏-招聘管理-数据录入
        self.date_entry_button = (By.XPATH, '//*[@id="sale$Menu"]/li[5]/a')
        # 手工添加数据
        self.enter_add_date = (By.XPATH, '//*[@class="addDiv___SG2W5"]')
        # 导入文件
        self.import_file = (By.XPATH,'//*[@class="ant-upload"]/input')
        # 模板下载
        self.file_upload = (By.LINK_TEXT,'模板下载')


        self.driver = driver
        self.wait = WebDriverWait(driver, 30)

        # 测试用例执行时去除
        # self.driver = webdriver.Chrome()

    def jump_to(self):
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.rec_management))
            self.driver.find_element(*self.rec_management).click()
            time.sleep(0.5)
            self.wait.until(expected_conditions.presence_of_element_located(self.date_entry_button))
            self.driver.find_element(*self.date_entry_button).click()
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/跳转至数据录入页面错误')
            raise e

    # 导入文件
    def import_date(self,file):
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.import_file))
            self.driver.find_element(*self.import_file).send_keys(f'{file}')
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/导入文件错误')
            raise e

    # 进入手工添加数据界面
    def add_date(self):
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.enter_add_date))
            self.driver.find_element(*self.enter_add_date).click()
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/输入密码错误.png')
            raise e



    def resume_upload(self):
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.file_upload))
            self.driver.find_element(*self.file_upload).click()
            time.sleep(2)
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/模板下载错误.png')
            raise e

    def template(self):
        pass
